var arr = ['logAnalysis.html'];
leftNaviFunc(arr);

$(function() {
    $('.searchTPLog').on('click', function() {
        var timeBegin = $('.timeBegin').val();
        var timeOver = $('.timeOver').val();
        var timeBeginNum = new Date("+$('.timeBegin').val()+").getTime(); //将时间转变成毫秒用来比较大小
        var timeOverNum = new Date("+$('.timeOver').val()+").getTime(); //将时间转变成毫秒用来比较大小
        var rootIp = $('.rootIp').val();
        var aimIp = $('.aimIp').val();
        var dataTime;
        if (timeBegin == '' || timeBegin == null || timeBegin == undefined) {
            layer.msg('请输入开始时间', { icon: 2 });
            return
        }
        if (timeOver == '' || timeOver == null || timeOver == undefined) {
            layer.msg('请输入结束时间', { icon: 2 });
            return
        }
        if (rootIp == '' || rootIp == null || rootIp == undefined || rootIp == /[^(\d*\.\d*\.\d*\.\d*)]/) {
            layer.msg('请输入源IP', { icon: 2 });
            return
        }
        if (aimIp == '' || aimIp == null || aimIp == undefined || aimIp == /[^(\d*\.\d*\.\d*\.\d*)]/) {
            layer.msg('请输入目的IP', { icon: 2 });
            return
        }

        $.ajax({
            // url: 'http://' + apihost + '/v1/TPLog',
            url: 'data.json',
            data: {},
            // data: { time: dataTime, org_src: rootIp, org_dst: aimIp },
            type: 'get',
            dataType: 'json',
            success: function(data) {
                $(".listContent").empty(); //清空listContent里面所有内容
                // if (data.message == "") {
                //     return
                // }
                if (data.result && data.result instanceof Array) {
                    var dateHtml = "";
                    dataTime = new Date("+data.result.time.val()+").getTime();
                    $.each(data.result, function(v) { //遍历数组里面的每一组对象
                        if (dataTime < timeBeginNum || dataTime > timeOverNum) {
                            return
                        }
                        if (rootIp != data.result.org_src) {
                            return
                        }
                        if (aimIp != data.result.org_dst) {
                            return
                        }
                        dateHtml += '<div class="listContent_item">';
                        dateHtml += '<div class="change"><span>' + data.result.time + '</span></div>';
                        dateHtml += '<div class="change"><span>' + data.result.org_src + '</span></div>';
                        dateHtml += '<div class="change"><span>' + data.result.org_dst + '</span></div>'
                        dateHtml += '<div class="change"><span>' + data.result.src + '</span></div>';
                        dateHtml += '<div class="change"><span>' + data.result.dst + '</span></div>';
                    })
                    $(".listContent").html(dateHtml);
                }
            },
            error: function() {
                layer.msg('TPLog search error', { icon: 2 });
            }
        })
    });
});